package starter.kit.rx.app.feature.book;

import android.os.Bundle;

import java.util.ArrayList;

import rx.Observable;
import starter.kit.feature.rx.RxResourcePresenter;
import starter.kit.feature.rx.RxStarterRecyclerFragment;
import starter.kit.rx.app.model.bean.book.Books;
import starter.kit.rx.app.network.ApiService;
import starter.kit.rx.app.network.service.DoubanService;

/**
 * ============================================================
 * 版权： xx 版权所有（c）2016
 * <p>
 * 作者：Loofer
 * 版本：1.0
 * 创建日期 ：2016/10/25 14:15.
 * 描述：
 * <p>
 * 注:如果您修改了本类请填写以下内容作为记录，如非本人操作劳烦通知，谢谢！！！
 * Modified Date Modify Content:
 * <p>
 * ==========================================================
 */
public class BookReadingPresenter extends RxResourcePresenter<Books> {

    private DoubanService mDoubanService;
    private int mPosition;
    private String mTitle;

    @Override
    protected void onCreate(Bundle savedState) {
        super.onCreate(savedState);
        mDoubanService = ApiService.creatDoubanService();
    }

    @Override
    protected void onTakeView(RxStarterRecyclerFragment rxStarterRecyclerFragment) {
        super.onTakeView(rxStarterRecyclerFragment);
        Bundle args= getView().getArguments();
        if(args!=null){
            mPosition = args.getInt("position");
            mTitle = args.getString("title");
        }
    }

    @Override
    public Observable<ArrayList<Books>> request(String previousKey, String nextKey, int pageSize) {

        return mDoubanService.searchBookByTag(mTitle,nextKey, pageSize).map(bookRoot -> (ArrayList<Books>) bookRoot.getBooks());
    }


}
